#include "usart.h"

void usart_init(uint32_t baud)
{
    uart_config_t uart_cfg = {
        .baud_rate = baud,
        .data_bits = UART_DATA_8_BITS,
        .parity = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
        .source_clk = UART_SCLK_APB,
        .rx_flow_ctrl_thresh = 122,
    };

    uart_param_config(UART_TYPE_NUM, &uart_cfg);

    uart_set_pin(UART_TYPE_NUM, UART_TX_PIN, UART_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
    uart_driver_install(UART_TYPE_NUM, RX_BUF_SIZE, RX_BUF_SIZE, 20, NULL, 0);
}

void uart1_init(uint32_t bound)
{
    uart_config_t uart_cfg = {
        .baud_rate = bound,
        .data_bits = UART_DATA_8_BITS,
        .parity = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
        .source_clk = UART_SCLK_APB,
        .rx_flow_ctrl_thresh = 122,
    };

    uart_param_config(UART_TRNAS_NUM, &uart_cfg);

    uart_set_pin(UART_TRNAS_NUM, UART_TRANS_TX_PIN, UART_TRANS_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
    uart_driver_install(UART_TRNAS_NUM, RX_BUF_SIZE, RX_BUF_SIZE, 20, NULL, 0);
}